<?php
// For initialization let the system report all
// kind of errors and warnings
error_reporting(E_ALL);

// Define basic constants(basically read-only system
// properties, that must not be altered).
define('KERNEL_START_TIME', $_SERVER['REQUEST_TIME_FLOAT']); // As of PHP >= 5.4
define('SYSTEM_DEFAULT_TIMEZONE', date_default_timezone_get());
define('DEFAULT_LOCALE', 'en-US');
define('PHP_SELF', filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_URL)); // A bit safer version of PHP_SELF
define('AVAILABLE_PHP_EXTENSIONS', '.php,.cache.php');

// Define directories names
define('APPDATA_DIR', 'AppData' . DIRECTORY_SEPARATOR);
define('CONFIG_DIR', APPDATA_DIR . 'Config' . DIRECTORY_SEPARATOR);
define('LOGS_DIR', APPDATA_DIR . 'Logs' . DIRECTORY_SEPARATOR);
define('CORE_DIR', 'Core' . DIRECTORY_SEPARATOR);
define('COMPONENTS_DIR', CORE_DIR . 'Components' . DIRECTORY_SEPARATOR);
define('DEBUGGING_DIR', COMPONENTS_DIR . 'Debugging' . DIRECTORY_SEPARATOR);
define('DEPENDENCY_FACTORY_DIR', COMPONENTS_DIR . 'DependencyFactory' . DIRECTORY_SEPARATOR);
define('DTO_DIR', COMPONENTS_DIR . 'DTO' . DIRECTORY_SEPARATOR);
define('LOCALIZATION_DIR', CORE_DIR . 'Localization' . DIRECTORY_SEPARATOR);
define('XML_DIR', COMPONENTS_DIR . 'XML' . DIRECTORY_SEPARATOR);

// Get an autoloader
require_once CORE_DIR . 'AppAutoloader.php';
$autoloader = new \Gotcha\Core\AppAutoloader(AVAILABLE_PHP_EXTENSIONS);

// Get a dependency factory and dependency container
/** @noinspection PhpIncludeInspection */
require_once DEPENDENCY_FACTORY_DIR . 'DependencyFactory.php';
/** @noinspection PhpIncludeInspection */
require_once DEPENDENCY_FACTORY_DIR . 'DependencyContainer.php';
$dependency = new \Gotcha\Core\Components\DependencyFactory\DependencyContainer(new \Gotcha\Core\Components\DependencyFactory\DependencyFactory());
$dependency->aggregateDependencies();

// Initialize error && exception handler
/** @noinspection PhpIncludeInspection */
require_once DEBUGGING_DIR . DIRECTORY_SEPARATOR . 'Handlers' . DIRECTORY_SEPARATOR . 'ErrorException.php';
/** @noinspection PhpIncludeInspection */
require_once DEBUGGING_DIR . DIRECTORY_SEPARATOR . 'Handlers' . DIRECTORY_SEPARATOR . 'Exception.php';
/** @noinspection PhpIncludeInspection */
require_once DEBUGGING_DIR . DIRECTORY_SEPARATOR . 'Handlers' . DIRECTORY_SEPARATOR . 'LibXML.php';
$errorHandler = new \Gotcha\Core\Components\Debugging\Handlers\ErrorException();
$errorHandler->setErrorExceptionHandler();
$exceptionHandler = new \Gotcha\Core\Components\Debugging\Handlers\Exception();
$exceptionHandler->setExceptionHandler();
$libXMLHandler = new \Gotcha\Core\Components\Debugging\Handlers\LibXML();
$libXMLHandler->setXMLErrorHandler();

// Initialize application
require_once CORE_DIR . 'AppKernel.php';
$kernel = new \Gotcha\Core\AppKernel($dependency);
$kernel->initializeBootstrap();

